/*
 *  TmpBreadCrumbs.cpp
 *  libavid
 *
 *  Created by Peter on 29.02.12.
 *  Copyright 2012 __MyCompanyName__. All rights reserved.
 *
 */

#include "TmpBreadCrumbs.h"
#include "AStream.h"

A_IMPLEMENT_CLASS( 'TMCS', TmpBreadCrumbs, AObject );

void TmpBreadCrumbs::readFromStream( AStream& str, const AObjDoc& objd )
{
	UInt8 tagMark, version;
	str.readPod( tagMark );
	str.readPod( version );
	TR_ASSERT( tagMark == 0x02 );
	TR_ASSERT( version == 0x01 );
	
	Int16 numCrumbs;
	str.readPod( numCrumbs );
	TR_ASSERT( numCrumbs >= 0);
	
	_crumbs.clear(); // TODO: This might leak memory in some situations!
	_crumbs.reserve( numCrumbs );
	
	for( int i = 0; i < numCrumbs; ++i ) {
		UInt32 theCrumb;
		str.readPod( theCrumb ); // TODO: Resolve to an ATmpCrumb pointer via AObjDoc
		_crumbs.push_back( theCrumb );
	}
	
	str.readPod( tagMark );
	TR_ASSERT( tagMark == 0x03 );
}

void TmpBreadCrumbs::dump( std::ostream& str ) const
{
	str << "TmpBreadCrumbs {" << std::endl;
	
	str << "\t_crumbs[ " << _crumbs.size() << " ] {" << std::endl;
	
	CrumbList::const_iterator it = _crumbs.begin();
	for( ; it != _crumbs.end(); ++it ) {
		str << "\t\t" << *it << std::endl;
	}
	
	str << "\t}" << std::endl;
	
	str << "}" << std::endl;
}